package kd.comt.plugin;

import java.util.EventObject;

import kd.bos.form.control.events.UploadEvent;
import kd.bos.form.control.events.UploadListener;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.form.control.ImageList;
import kd.bos.util.StringUtils;

public class Album_new extends AbstractFormPlugin implements UploadListener{
    private final String IMAGE_LIST_NUM = "bpgx_imagelistap";
    private final String IMAGE_LIST_URLS = "bpgx_xcdwb_tag";
    @Override
    public void upload(UploadEvent evt) {
        UploadListener.super.upload(evt);
        String key = evt.getCallbackKey();
        if (key.equals(IMAGE_LIST_NUM)) {
            Object[] imageLists = evt.getUrls();
            String url = imageLists[0].toString() + ";";
            String urls = this.getModel().getValue(IMAGE_LIST_URLS).toString();
            this.getModel().setValue(IMAGE_LIST_URLS, urls + url);
        }
    }

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);
        ImageList imageList = this.getView().getControl(IMAGE_LIST_NUM);
        String imageUrls = (String) this.getModel().getValue(IMAGE_LIST_URLS);
        if (StringUtils.isEmpty(imageUrls)) {
            return;
        }
        String[] urls = imageUrls.split(";");
        imageList.setImageUrls(urls);
    }

    @Override
    public void registerListener(EventObject e) {
        super.registerListener(e);
        ImageList imageList = this.getView().getControl("bpgx_imagelistap");
        imageList.addUploadListener(this);
    }
}
